
import random

from sprite import *
from common import *

class Bird(GameSprite):
	
	def __init__(self, **kwargs):
		GameSprite.__init__(self, "bird.png", **kwargs)
		if random.randint(0,1) == 1:
			self.right = True
			self.left = False
		else:
			self.right = False
			self.left = True
		self.y = 500
		self.speed = 200
		self.dammage = 3
		self.health = 2
		self.name = "bird"
		self.jump_force = 400
		self.height = random.randint(7,21)
	
	def update(self, dt):
		GameSprite.update(self, dt)
		for y in range(1, self.height):
			if (map.is_ground(self.x, self.y - (y * 10))):
				self.jump_force = (self.height - y) * 10
				self.jump()
				break
	
	def jump(self):
		self.y += 1
		self.vertical += self.jump_force
	
	def die(self):
		GameSprite.die(self)
		if (self.killed_by == "player"):
			kill_bird()